package com.project.dao.impl;

import java.sql.SQLException;

import com.project.common.util.QueryUtils;
import com.project.dao.ICustomerDao;
import com.project.dao.bean.Customer;

public class CustomerDaoImpl extends BaseDaoImpl implements ICustomerDao{

	//分页显示方法
	public QueryUtils customerlist(QueryUtils queryUtils) {
		//求出总的数据记录数
		System.out.println("进入了customerdaoimpl方法。。");
		try {
			queryUtils.setPagetotal(Long.parseLong(this.getSqlMapClient().queryForObject("customercount").toString()));
			System.out.println("页数："+queryUtils.getPagesum());
			queryUtils.setPagelist(this.getSqlMapClient().queryForList("customerlist", queryUtils));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}	
		
		return queryUtils;
	}

	//删除方法
	public int delete(long id) {
		System.out.println("进入了customerdaoimpl中的delete方法。。");
		int flag=0;
		try {
			flag=this.getSqlMapClient().delete("deletecustomer", id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

	//findbyid方法
	public Customer findbyid(long id) {
		System.out.println("进入了customerdaoimpl中的findbyid方法。。");
		//System.out.println("daoimpl传入的id"+id);
		Customer customer=new Customer();
		try {
			customer=(Customer) this.getSqlMapClient().queryForObject("findbyidcustomer", id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return customer;
	}

	//更新方法
	public int update(Customer customer) {
		System.out.println("进入了customerdaoimpl重点额update方法。。");
		int flag=0;
		try {
			flag=this.getSqlMapClient().update("updatecustomer",customer);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return flag;
	}

}
